package com.demo.richText.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.demo.richText.pojo.ArticleFile;
import com.demo.richText.mapper.ArticleFileMapper;
import com.demo.richText.service.ArticleFileService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 小王八
 * @since 2022-09-05
 */
@Service
public class ArticleFileServiceImpl extends ServiceImpl<ArticleFileMapper, ArticleFile> implements ArticleFileService {

    @Autowired
    private ArticleFileMapper articleFileMapper;

    @Override
    public Boolean toSaveFile(List<String> fileUrl, Long articleId) {
        List<ArticleFile> articleFiles=new ArrayList<>();
        fileUrl.forEach(item->{
            articleFiles.add(new ArticleFile().setFileUrl(item).setArticleId(articleId));
        });
        return saveBatch(articleFiles);
    }

    @Override
    public List<ArticleFile> queryFileListByArtId(Long articleId) {
        QueryWrapper<ArticleFile> wrapper = new QueryWrapper<>();
        wrapper.select("pk_id","file_url")
                .eq("article_id",articleId);
        return articleFileMapper.selectList(wrapper);
    }
}
